﻿using System;
using System.Windows.Controls;

namespace SilverlightTraining_Stelmakh.Controls
{
	public partial class DigitalClock : UserControl
	{
		public DigitalClock()
		{
			InitializeComponent();
			ShowCurrentTime(null, null);
			var timer = new System.Windows.Threading.DispatcherTimer();
			timer.Interval = new TimeSpan(0, 0, 15);
			timer.Tick += ShowCurrentTime;
			timer.Start();
		}

		void ShowCurrentTime(object sender, EventArgs e)
		{
			Hours.Text = DateTime.Now.Hour.ToString().Length < 2
			             	? "0" + DateTime.Now.Hour.ToString()
			             	: DateTime.Now.Hour.ToString();
			Minutes.Text = DateTime.Now.Minute.ToString().Length < 2
			               	? "0" + DateTime.Now.Minute.ToString()
			               	: DateTime.Now.Minute.ToString();
		}
	}
}
